package mdl

import (
	. "hotime"
	"net/http"
	"io/ioutil"
	"github.com/opesun/goquery"
	"github.com/axgle/mahonia"

	"strings"
)

type OuZhi struct {
	
}

func(this *OuZhi)Info(fid string) map[string]Map{

	data:=map[string]Map{}


	var url = "http://odds.500.com/fenxi/ouzhi-" + fid + ".shtml"
	client := http.Client{}
	res, _ := client.Get(url)
	defer res.Body.Close()
	body, err := ioutil.ReadAll(res.Body)
	p, err := goquery.ParseString(mahonia.NewDecoder("gbk").ConvertString(string(body)))
	if err != nil {
		panic(err)
		return data
	}

	trs := p.Find("#datatb")
	trs = trs.Find(".tr1")

	for i := 0; i < trs.Length(); i++ {
		tds := trs.Eq(i)
		tables := tds.Find(".pl_table_data")
		tds = tds.Find("td")
		//		fmt.Println(trs.Eq(i).Html())
		yazhi := Map{"fid": fid}
		a := tds.Eq(1)
		yazhi["quancheng"] = a.Attr("title")
		a = a.Find("a")
		yazhi["quanchenghref"] = a.Attr("href")

		table0 := tables.Eq(1)
		ttds := table0.Find("td")
		yazhi["sheng"] = strings.Replace(ttds.Eq(0).Text(),"%","",-1)
		yazhi["ping"] = strings.Replace(ttds.Eq(1).Text(),"%","",-1)
		yazhi["fu"] = strings.Replace(ttds.Eq(2).Text(),"%","",-1)
		data[yazhi.GetString("quancheng")]=yazhi;
	}


	return data
}